package top.huxy.boot.model.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import top.huxy.boot.exception.RequestParamIllegalException;
import top.huxy.boot.model.dto.DTOSchedule;
import top.huxy.boot.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @author huxy
 * @date 2021-08-29
 **/
@Data
@NoArgsConstructor
public class ScheduleJob implements Serializable {

    /**
     * 任务id
     **/
    private Integer jobId;

    /**
     * spring bean名称
     **/
    private String beanName;

    /**
     * 方法名
     **/
    private String methodName;

    /**
     * 参数
     **/
    private String param;

    /**
     * cron表达式
     **/
    private String cron;

    /**
     * 启用/停止
     **/
    private Boolean enable;

    /**
     * 备注
     **/
    private String remark;

    private long createTime=System.currentTimeMillis();

    private Date updateTime;

    private Integer adminId;

    private String adminName;

    public ScheduleJob(DTOSchedule dtoSchedule, Integer adminId) {
        this.beanName = dtoSchedule.getBeanName();
        this.methodName = dtoSchedule.getMethodName();
        this.param = dtoSchedule.getParam();
        this.cron = dtoSchedule.getCron();
        this.enable = dtoSchedule.getEnable();
        this.remark = dtoSchedule.getRemark();
        this.adminId = adminId;

        this.test();
    }

    private void test() {
        String temp;
        if (null != (temp = StringUtils.getEmptyParamName("beanName,methodName,cron,adminId", beanName, methodName, cron, adminId))) {
            throw new RequestParamIllegalException("param [" + temp + "] is required");
        }
    }
}
